home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg4.cab / test_ntpath.py < prev    next >
Text File  |  2005-11-19  |  5KB  |  135 lines

  1. import ntpath
  2. from test.test_support import verbose, TestFailed
  3. import os
  4.  
  5. errors = 0
  6.  
  7. def tester(fn, wantResult):
  8.     global errors
  9.     fn = fn.replace("\\", "\\\\")
  10.     gotResult = eval(fn)
  11.     if wantResult != gotResult:
  12.         print "error!"
  13.         print "evaluated: " + str(fn)
  14.         print "should be: " + str(wantResult)
  15.         print " returned: " + str(gotResult)
  16.         print ""
  17.         errors = errors + 1
  18.  
  19. tester('ntpath.splitext("foo.ext")', ('foo', '.ext'))
  20. tester('ntpath.splitext("/foo/foo.ext")', ('/foo/foo', '.ext'))
  21. tester('ntpath.splitext(".ext")', ('', '.ext'))
  22. tester('ntpath.splitext("\\foo.ext\\foo")', ('\\foo.ext\\foo', ''))
  23. tester('ntpath.splitext("foo.ext\\")', ('foo.ext\\', ''))
  24. tester('ntpath.splitext("")', ('', ''))
  25. tester('ntpath.splitext("foo.bar.ext")', ('foo.bar', '.ext'))
  26. tester('ntpath.splitext("xx/foo.bar.ext")', ('xx/foo.bar', '.ext'))
  27. tester('ntpath.splitext("xx\\foo.bar.ext")', ('xx\\foo.bar', '.ext'))
  28.  
  29. tester('ntpath.splitdrive("c:\\foo\\bar")',
  30.        ('c:', '\\foo\\bar'))
  31. tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")',
  32.        ('\\\\conky\\mountpoint', '\\foo\\bar'))
  33. tester('ntpath.splitdrive("c:/foo/bar")',
  34.        ('c:', '/foo/bar'))
  35. tester('ntpath.splitunc("//conky/mountpoint/foo/bar")',
  36.        ('//conky/mountpoint', '/foo/bar'))
  37.  
  38. tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
  39. tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")',
  40.        ('\\\\conky\\mountpoint\\foo', 'bar'))
  41.  
  42. tester('ntpath.split("c:\\")', ('c:\\', ''))
  43. tester('ntpath.split("\\\\conky\\mountpoint\\")',
  44.        ('\\\\conky\\mountpoint', ''))
  45.  
  46. tester('ntpath.split("c:/")', ('c:/', ''))
  47. tester('ntpath.split("//conky/mountpoint/")', ('//conky/mountpoint', ''))
  48.  
  49. tester('ntpath.isabs("c:\\")', 1)
  50. tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1)
  51. tester('ntpath.isabs("\\foo")', 1)
  52. tester('ntpath.isabs("\\foo\\bar")', 1)
  53.  
  54. tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
  55.        "/home/swen")
  56. tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
  57.        "\\home\\swen\\")
  58. tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
  59.        "/home/swen/spam")
  60.  
  61. tester('ntpath.join("")', '')
  62. tester('ntpath.join("", "", "")', '')
  63. tester('ntpath.join("a")', 'a')
  64. tester('ntpath.join("/a")', '/a')
  65. tester('ntpath.join("\\a")', '\\a')
  66. tester('ntpath.join("a:")', 'a:')
  67. tester('ntpath.join("a:", "b")', 'a:b')
  68. tester('ntpath.join("a:", "/b")', 'a:/b')
  69. tester('ntpath.join("a:", "\\b")', 'a:\\b')
  70. tester('ntpath.join("a", "/b")', '/b')
  71. tester('ntpath.join("a", "\\b")', '\\b')
  72. tester('ntpath.join("a", "b", "c")', 'a\\b\\c')
  73. tester('ntpath.join("a\\", "b", "c")', 'a\\b\\c')
  74. tester('ntpath.join("a", "b\\", "c")', 'a\\b\\c')
  75. tester('ntpath.join("a", "b", "\\c")', '\\c')
  76. tester('ntpath.join("d:\\", "\\pleep")', 'd:\\pleep')
  77. tester('ntpath.join("d:\\", "a", "b")', 'd:\\a\\b')
  78. tester("ntpath.join('c:', '/a')", 'c:/a')
  79. tester("ntpath.join('c:/', '/a')", 'c:/a')
  80. tester("ntpath.join('c:/a', '/b')", '/b')
  81. tester("ntpath.join('c:', 'd:/')", 'd:/')
  82. tester("ntpath.join('c:/', 'd:/')", 'd:/')
  83. tester("ntpath.join('c:/', 'd:/a/b')", 'd:/a/b')
  84.  
  85. tester("ntpath.join('')", '')
  86. tester("ntpath.join('', '', '', '', '')", '')
  87. tester("ntpath.join('a')", 'a')
  88. tester("ntpath.join('', 'a')", 'a')
  89. tester("ntpath.join('', '', '', '', 'a')", 'a')
  90. tester("ntpath.join('a', '')", 'a\\')
  91. tester("ntpath.join('a', '', '', '', '')", 'a\\')
  92. tester("ntpath.join('a\\', '')", 'a\\')
  93. tester("ntpath.join('a\\', '', '', '', '')", 'a\\')
  94.  
  95. tester("ntpath.normpath('A//////././//.//B')", r'A\B')
  96. tester("ntpath.normpath('A/./B')", r'A\B')
  97. tester("ntpath.normpath('A/foo/../B')", r'A\B')
  98. tester("ntpath.normpath('C:A//B')", r'C:A\B')
  99. tester("ntpath.normpath('D:A/./B')", r'D:A\B')
  100. tester("ntpath.normpath('e:A/foo/../B')", r'e:A\B')
  101.  
  102. # Next 3 seem dubious, and especially the 3rd, but normpath is possibly
  103. # trying to leave UNC paths alone without actually knowing anything about
  104. # them.
  105. tester("ntpath.normpath('C:///A//B')", r'C:\\\A\B')
  106. tester("ntpath.normpath('D:///A/./B')", r'D:\\\A\B')
  107. tester("ntpath.normpath('e:///A/foo/../B')", r'e:\\\A\B')
  108.  
  109. tester("ntpath.normpath('..')", r'..')
  110. tester("ntpath.normpath('.')", r'.')
  111. tester("ntpath.normpath('')", r'.')
  112. tester("ntpath.normpath('/')", '\\')
  113. tester("ntpath.normpath('c:/')", 'c:\\')
  114. tester("ntpath.normpath('/../.././..')", '\\')
  115. tester("ntpath.normpath('c:/../../..')", 'c:\\')
  116. tester("ntpath.normpath('../.././..')", r'..\..\..')
  117. tester("ntpath.normpath('K:../.././..')", r'K:..\..\..')
  118.  
  119. # ntpath.abspath() can only be used on a system with the "nt" module
  120. # (reasonably), so we protect this test with "import nt".  This allows
  121. # the rest of the tests for the ntpath module to be run to completion
  122. # on any platform, since most of the module is intended to be usable
  123. # from any platform.
  124. try:
  125.     import nt
  126. except ImportError:
  127.     pass
  128. else:
  129.     tester('ntpath.abspath("C:\\")', "C:\\")
  130.  
  131. if errors:
  132.     raise TestFailed(str(errors) + " errors.")
  133. elif verbose:
  134.     print "No errors.  Thank your lucky stars."
  135.